package com.ymatou.iapi.sellerquery.service;

import java.util.ArrayList;

import org.json.JSONObject;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.ymatou.iapi.sellerquery.parameter.resp.CreditInfoListResp;
import com.ymatou.iapi.sellerquery.parameter.resp.OrderHistoryListResp;
import com.ymt.base.YmatouBaseCall;
import com.ymttest.utils.EnvSetup;

/**
 * 获取订单历史Call FreeMaker Template自动生成代码
 */
public class GetOrderHistoryCall extends YmatouBaseCall {
	private static String opurl = "api/SellerQuery/GetOrderHistory";

	public GetOrderHistoryCall() {
		super(EnvSetup.getSystemUrl("sellerquery_iapi"), opurl, "GET", "PARAM");
	}

	@Override
	public void addDefHeader() {
		client.addHeader("Accept", "text/xml,text/javascript,text/html,application/json");
		client.addHeader("Content-Type", "application/json; charset=UTF-8");
	}
	
	
	/**
	 * @return
	 */
	public ArrayList<OrderHistoryListResp> getResult() {
		ArrayList<OrderHistoryListResp> result =new ArrayList<OrderHistoryListResp>();
		try {
			String historyList=new JSONObject(getString("data")).getString("orderHistoryList");
			result = (ArrayList<OrderHistoryListResp>) new Gson().fromJson(historyList, new TypeToken<ArrayList<OrderHistoryListResp>>() {}.getType());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

	/**
	 * 获取Code
	 * 
	 * @return
	 */
	public String getCode() {
		String Code = null;
		try {
			Code = new JSONObject(getReturnData()).getString("code");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return Code;
	}

	/**
	 * 获取BCode
	 * 
	 * @return
	 */
	public String getBCode() {
		String BCode = null;
		try {
			BCode = new JSONObject(getReturnData()).getString("bcode");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return BCode;
	}

	/**
	 * 获取Msg
	 * 
	 * @return
	 */
	public String getMsg() {
		String BCode = null;
		try {
			BCode = new JSONObject(getReturnData()).getString("msg");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return BCode;
	}

	/**
	 * 获取Data
	 * 
	 * @return
	 */
	public JSONObject getData() {
		JSONObject Data = null;
		try {
			Data = new JSONObject(getReturnData()).getJSONObject("Data");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return Data;
	}
}
